package skiree.host.abetsy.api.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import skiree.host.abetsy.model.LocalEpisode;

@Aspect
@Component
public class EventQueueAspect {

    @Autowired
    private EventQueueServer eventQueueServer;

    @Pointcut("@annotation(skiree.host.abetsy.api.annotation.EventQueue)")
    public void eventQueue() {
    }

    @Around("eventQueue()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        LocalEpisode localEpisode = (LocalEpisode) joinPoint.getArgs()[0];
        EventQueueModel queueModel = eventQueueServer.initEventQueue(localEpisode);
        if(queueModel == null) return null;
        return eventQueueServer.addToEventQueue(queueModel);
    }

}




